package cn.shop.thiredparty.util;

import cn.shop.thiredparty.entity.Metadata;
import com.aliyun.oss.model.ObjectMetadata;

public class MetadataHelper {
	
	public static ObjectMetadata toObjectMetadata(Metadata metadata) {
		if (metadata == null)
			return null;
		
		ObjectMetadata om = new ObjectMetadata();
		if (metadata.getContentType() != null)
			om.setContentType(metadata.getContentType());
		if (metadata.getContentLength() > 0)
			om.setContentLength(metadata.getContentLength());
		if (metadata.getContentMd5() != null)
			om.setContentMD5(metadata.getContentMd5());
		if (metadata.getLastModified() != null)
			om.setLastModified(metadata.getLastModified());
		return om;
	}
	
	public static Metadata fromObjectMetadata(ObjectMetadata om) {
		if (om == null)
			return null;
		
		Metadata metadata = new Metadata();
		metadata.setContentType(om.getContentType());
		metadata.setContentLength(om.getContentLength());
		metadata.setContentMd5(om.getContentMD5());
		metadata.setLastModified(om.getLastModified());
		return metadata;
	}

}
